package org.rabbit;

import javax.annotation.Resource;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@RabbitListener(queues= {"fanoutqueue2"})
@Component
public class MailMessageReciver {

	@Resource
	private JavaMailSender ms;   //springboot自动创建发邮件的对象
	
	@RabbitHandler
	public void process(String to) {
		
		SimpleMailMessage sm = new SimpleMailMessage();
		sm.setFrom("758770768@qq.com");    //邮箱来自哪里
		sm.setTo(to);    //发给谁
		sm.setText("你好！");     //发送的内容
		ms.send(sm);
 	}
	
}
